package com.jiesen.base.modules.login.branch.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiesen.base.baseDao.BaseServiceImpl;
import com.jiesen.base.modules.login.branch.mapper.BranchDao;
import com.jiesen.base.modules.login.branch.model.Branch;
import com.jiesen.base.modules.login.branch.service.BranchService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BranchServiceImpl extends BaseServiceImpl<BranchDao, Branch> implements BranchService {

    //根据区域id查询包含的分校信息
    @Override
    public List<Branch> findBranchByParentId(Integer id) {
        QueryWrapper<Branch> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id",id);
        List<Branch> branches = baseMapper.selectList(queryWrapper);
        return branches;
    }

    //根据区域id查询区域信息
    @Override
    public Branch findBranchChildById(Integer id) {
        Branch branch = baseMapper.selectById(id);
        branch.setBranchs(findBranchByParentId(id));
        return branch;
    }

    @Override
    public List<Branch> findBranchSchool() {
        Branch branch = baseMapper.selectById(1);
        QueryWrapper<Branch> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("parent_id",0);
        List<Branch> branches = baseMapper.selectList(queryWrapper);
        branches.add(branch);
        return branches;
    }


}
